#include <stdio.h>
#include <string.h>

int cmp (char *x, char *y)
{
    const char *a = x;
    const char *b = y;
    return *a < *b ? -1 : *a > *b;
}

int main(int argc, char *argv[])
{
    char word[BUFSIZ];
    char temp[BUFSIZ];
    char scramble[BUFSIZ];
    FILE *f;

    if (argc != 2) return(1);
    snprintf(scramble, sizeof(scramble) - 1, "%s", argv[1]);
    qsort(scramble,strlen(scramble),1,cmp);
    f=fopen("wordlist.txt","r");
    if(!f) return(1);

    while (!feof(f)) {
	fgets(word, sizeof(word), f);
	word[strlen(word)-1] = 0;
	if (strlen(scramble) != strlen(word)) continue;
	sprintf(temp,"%s",word);
	qsort (temp, strlen(temp), 1, cmp);
	if (!strncmp(scramble,temp,strlen(temp))) {
	    printf("ketemu: %s !\n", word);
	    return(0);
        }
    }
    printf("nangis di pojokan.\n");
    return(1);
}

/* by @mokiatsu */
